<?php
/*
 *   This file is part of poat.
 *
 *   poat is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat.  If not, see <http://www.gnu.org/licenses/>.
 */

require_once(ROOT_PATH."class/team.class.php");

if ($CURRENT_USER->groupid == GROUP_ADMIN) {
	$team = new team;
	$team->status=STATUS_ACTIVE;
	$tlist = $loader->loadListBy($team,$team->listByStatus());
} else {
	$team = new team;
	$team->id=$CURRENT_USER->teamid;
	$loader->get($team);
	$tlist = array();
	array_push($tlist,$team);
}

$teamstats=array();
foreach ($tlist as $t) {
	$sql = "SELECT teamid, statusid, count(id) as count, sum(translated) sutr, sum(untranslated) suun, sum(fuzzy) as sufu FROM ".FILES.PROJECT_PREFIX.$prjid." WHERE teamid = ".util::str($t->id)." GROUP BY teamid, statusid";	
	$list = $loader->fetchlist($sql);
	$temp = array();
	$temp['team'] = $t->name;
	$total = 0;
	$trans = 0;
	$untrans = 0;
	$fuzzy= 0;
	foreach ($FILE_STATUS_LIST as $fs) {
		$temp[trim($fs)] = 0;
	}
	foreach ($list as $c) {
		$temp[$c['statusid']] = $c['count'];
		$total += $c['count'];
		$trans +=$c['sutr'];
		$untrans +=$c['suun'];
		$fuzzy +=$c['sufu'];
	}
	$temp['totalfiles']=$total;
	$temp['totalstrings']=$trans+$untrans+$fuzzy;
	$temp['totaltranslated']=$trans;
	$temp['totalunstranslated']=$untrans;
	$temp['totalfuzzy']=$fuzzy;
	array_push($teamstats,$temp);
}

$tm->assign('teamstats',$teamstats);		
$content = $tm->fetch('teamstats.tpl');	

?>